using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bartteshieldshield : shield
{
    public float CD;
    private float CDtime;
    GameObject playerobject;
    Creation player;
    private CircleCollider2D collider2D;
    private SpriteRenderer spriterenderer;
    public float health;
    public float recoveryratio;
    public float maxhealth;
    bool gameend;
    // Start is called before the first frame update
    void Start()
    {
        collider2D = GetComponent<CircleCollider2D>();
        spriterenderer = GetComponent<SpriteRenderer>();
        player = GetComponentInParent<Creation>();
        spriterenderer.enabled = false;
        collider2D.enabled = false;
        maxhealth = 250f;
        gameend = true;
    }
    public override void TakeDamage(float Damage)
    {
        health -= Damage;
        if (health <= 0)
        {
            skillend();
        }

        //StartCoroutine(Stiff());
    }
    // Update is called once per frame
    void skillend()
    {
        player.attackable=true;
        spriterenderer.enabled = false;
        collider2D.enabled = false;
        CDtime = CD;
        gameend = true;
    }
    void Skill()
    {
        health = maxhealth;
        spriterenderer.enabled = true;
        collider2D.enabled = true;
        player.attackable=false;
        gameend = false;
    }
    void Update()
    {
        if (CDtime > 0)
        {
            CDtime -= Time.deltaTime;
        }
         if (gameend == true && CDtime <= 0)
          {
               Skill();

           }
        if (spriterenderer.enabled == true)
        {
            health += recoveryratio * maxhealth;
            if (health > maxhealth) health = maxhealth;
            Color temp = spriterenderer.color;
            temp.a = 1f * health / maxhealth;
            spriterenderer.color = temp;
        }
    }
}
